# SOME BASIC ANALYSIS SCRIPTS
import numpy
from scipy import *
from brian import *
import time


def calc_stats_monitor(M,nexc,ninh): # returns the mean, std of the mean, the std and the std of the std
    M_exc=M.values[0:nexc]
    M_inh=M.values[nexc:nexc+ninh]
    
    Mean_mean={}
    Std_mean={}
    Mean_std={}
    Std_std={}

    Mean_mean['exc']=numpy.mean(numpy.mean(M_exc,1))
    Std_mean['exc']=numpy.std(numpy.mean(M_exc,1))

    Mean_std['exc']=numpy.mean(numpy.std(M_exc,1))
    Std_std['exc']=numpy.std(numpy.std(M_exc,1))

    Mean_mean['inh']=numpy.mean(numpy.mean(M_inh,1))
    Std_mean['inh']=numpy.std(numpy.mean(M_inh,1))

    Mean_std['inh']=numpy.mean(numpy.std(M_inh,1))
    Std_std['inh']=numpy.std(numpy.std(M_inh,1))

    print "Excitatory mean = ", Mean_mean['exc'], "+-", Std_mean['exc']
    print "Excitatory std = ", Mean_std['exc'], "+-", Std_std['exc']
    print "Inhibitory mean = ",  Mean_mean['inh'], "+-", Std_mean['inh']
    print "Inhibitory std = ",  Mean_std['inh'], "+-", Std_std['inh']

    return Mean_mean, Std_mean, Mean_std, Std_std



def calc_stats_monitor_loop(M,nexc,ninh): # returns the mean, std of the mean, the std and the std of the std
    M_exc=M.values[0:nexc]
    M_inh=M.values[nexc:nexc+ninh]
    
    Exc_val={}
    Inh_val={}

    Mean_mean={}
    Std_mean={}
    Mean_std={}
    Std_std={}

    Exc_val['Mean_mean']=numpy.mean(numpy.mean(M_exc,1))
    Exc_val['Std_mean']=numpy.std(numpy.mean(M_exc,1))

    Mean_std['exc']=numpy.mean(numpy.std(M_exc,1))
    Std_std['exc']=numpy.std(numpy.std(M_exc,1))

    Mean_mean['inh']=numpy.mean(numpy.mean(M_inh,1))
    Std_mean['inh']=numpy.std(numpy.mean(M_inh,1))

    Mean_std['inh']=numpy.mean(numpy.std(M_inh,1))
    Std_std['inh']=numpy.std(numpy.std(M_inh,1))

    print "Excitatory mean = ", Mean_mean['exc'], "+-", Std_mean['exc']
    print "Excitatory std = ", Mean_std['exc'], "+-", Std_std['exc']
    print "Inhibitory mean = ",  Mean_mean['inh'], "+-", Std_mean['inh']
    print "Inhibitory std = ",  Mean_std['inh'], "+-", Std_std['inh']

    return Mean_mean, Std_mean, Mean_std, Std_std

